From 840c72d74db5d3b04c3d7d706c8cd092e3963580 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sun, 2 Apr 2023 18:23:21 -0300 Subject: [PATCH] gsk/vulkan/buffer: Pass aligned memory value This was a tricky one to figure out, but it's pretty simple to understand (I hope!). So, this AMD card I'm using requires buffer memory sizes to be aligned to 16 bytes. Intel is aligned to 4 bytes I think, but AMD - or at least this AMD model in particular - uses 16 bytes for alignment. When creating a a particular texture (I did not determin which one specifically!) a buffer of size 1276 bytes is requested. 1276 / 16 = 79.75, which is clearly not aligned to the required 16 bytes. We request Vulkan to create a buffer of 1276 bytes for us, it figures out that it's not aligned, and creates a buffer of 1280 bytes, which is aligned. The extra 4 bytes are wasted, but that's okay. We immediately query this buffer for this exact information, using vkGetBufferMemoryRequirements(), and proceed to create actual memory to back this buffer up. The buffer tells us we must use 1280 bytes, so we pass 1280 bytes and everyone is happy, right? Of course not. We pass 1276 bytes, and Vulkan is subtly unhappy at us. Fix that by passing the value that Vulkan asks us to use, i.e., the size returned by vkGetBufferMemoryRequirements(). --- gsk/vulkan/gskvulkanbuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsk/vulkan/gskvulkanbuffer.c b/gsk/vulkan/gskvulkanbuffer.c index b73907faea..21ce89bd31 100644 --- a/gsk/vulkan/gskvulkanbuffer.c +++ b/gsk/vulkan/gskvulkanbuffer.c @@ -46,7 +46,7 @@ gsk_vulkan_buffer_new_internal (GdkVulkanContext *context, self->memory = gsk_vulkan_memory_new (context, requirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - size); + requirements.size); GSK_VK_CHECK (vkBindBufferMemory, gdk_vulkan_context_get_device (context), self->vk_buffer, -- 2.30.2